
package qreasymarket.movil;

import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class AlertaDeliveryActivity extends Activity {

	TextView user_actual;
	Button comenzar;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.popup_iniciar_qr);
		comenzar = (Button) findViewById(R.id.comenzarbtn);
		user_actual = (TextView) findViewById(R.id.user_actual);

		Intent intention = getIntent();
		Bundle datos = intention.getExtras();
		user_actual.setText(datos.getString("valor1"));
		String userID = user_actual.getText().toString();
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

	}

	public void btnEnviar(View view) {

		Intent intention = getIntent();
		Bundle datos = intention.getExtras();
		user_actual.setText(datos.getString("valor1"));
		String userID = user_actual.getText().toString();

		RestClient cliente1 = new RestClient(
				"http://192.168.1.176:8080/QR-EasyMarket_Web/rest/capturar_idcliente");
		cliente1.AddParam("email", userID);

		try {
			cliente1.Execute(RequestMethod.GET);
			String jsontext = cliente1.getResponse();
			Log.i("AlertaDeliveryActivity", jsontext);

			JSONArray entries = new JSONArray(jsontext);

			jsontext = jsontext.toLowerCase().trim();

			int b;

			for (b = 0; b < entries.length(); b++) {

				JSONObject post = entries.getJSONObject(b);
				String idXxxx = post.getString("idCliente");
				String nombres=post.getString("nombres");
				String apaterno =post.getString("apaterno");
				String amaterno = post.getString("amaterno");
				
				String completo = nombres+ " " +apaterno+" "+amaterno;
				
				System.out.println(idXxxx);
				Log.i("AlertaDeliveryActivity", idXxxx);

				Intent a = new Intent(AlertaDeliveryActivity.this, ListaCompraActivity.class);
				Bundle user = new Bundle();
				user.putString("id", idXxxx);
				user.putString("nom", completo);
				a.putExtras(user);
				startActivity(a);

			}

		} catch (Exception e) {
			Log.i("AlertaDeliveryActivity", "ERROR:" + e.getMessage());
		}

	}
}
